package com.pan.controller.Operations;

import com.pan.aop.BusinessType;
import com.pan.aop.MyLog;
import com.pan.controller.tools.Methods;
import com.pan.controller.tools.R1;
import com.pan.service.IOperaterService;
import com.pan.service.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/deptnochange")
@Tag(name = "DeptnoController",description = "操作员修改部门")
public class DeptnoController {
    @Autowired
    private IOperaterService operaterService;
    @Autowired
    private IUserService userService;

    Methods methods = new Methods();

    //操作员修改部门
    @Operation(summary = "操作员修改部门",description ="不能修改管理员的部门" )
    @PutMapping
    @MyLog(title = "操作员修改部门",optParam = "#{id},#{deptno}",businessType = BusinessType.UPDATE)
    public R1 changeDeptno(@Parameter(description = "编号",required = true,example = "1") @RequestParam Integer id,
                           @Parameter(description = "新的部门",required = true,example = "研发部门") @RequestParam Integer deptno,
                           HttpServletRequest request) {
        //检查用户权限
        if (methods.isRenShi(request,userService)){
            return new R1(operaterService.changeDeptno(id, deptno));
        }
        return new R1(false,"权限不足");
    }
}
